/**
 * 进入房间准备阶段,所有用户一致；包括房主
 * 1.如果能执行到这里,其实在前面的main层，就已经在tt_room里占掉一个名额了；如果名额没有占成功，是不允许被进入到这里来的
 */
var RoomRealyLayer = cc.Layer.extend({
    //realy_bg
    realy_bg:null,
    realy_size:null,
    realy_user_face_1:null,//1,2,3,4 分别为自己，右侧，对面，上侧
    ws_user_1:null,ws_user_2:null,ws_user_3:null,ws_user_4:null,//1,2,3,4分别为自己，下家，对面，上家
    //初始化结构函数
    ctor:function () {
        this._super();
        this.realy_size = cc.director.getWinSize();
        this.draw_realy_bg();
        this.draw_user_face();
        this.draw_friend_and_dissolution();
        /****启动ws-room-realy计时器,开始监听房间信息**********************************************************************/
        this.schedule( this.draw_timer_room_realy , 0.1 );
        /****启动ws-room-realy计时器,开始监听房间信息**********************************************************************/
        return true;
    },
    //绘制牌桌背景图
    draw_realy_bg:function(){
        this.realy_bg   = cc.Sprite.create( res.Realy_BG );
        this.realy_bg.x = this.realy_size.width / 2;
        this.realy_bg.y = this.realy_size.height / 2;
        this.addChild(this.realy_bg,0);
    },
    //绘制四个边角用户头像框及名称、胡息元素
    draw_user_face:function(){
        this.realy_user_face_1   = cc.Sprite.create( res.Realy_FACE );
        this.realy_user_face_1.x = ROOM_FACE_CPOINT;
        this.realy_user_face_1.y = ROOM_FACE_CPOINT;
        this.realy_user_face_2   = cc.Sprite.create( res.Realy_FACE );
        this.realy_user_face_2.x = this.realy_size.width - ROOM_FACE_CPOINT;
        this.realy_user_face_2.y = ROOM_FACE_CPOINT;
        this.realy_user_face_3   = cc.Sprite.create( res.Realy_FACE );
        this.realy_user_face_3.x = this.realy_size.width - ROOM_FACE_CPOINT;
        this.realy_user_face_3.y = this.realy_size.height - ROOM_FACE_CPOINT - ROOM_FACE_CPOINT / 2;
        this.realy_user_face_4   = cc.Sprite.create( res.Realy_FACE );
        this.realy_user_face_4.x = ROOM_FACE_CPOINT;
        this.realy_user_face_4.y = this.realy_size.height - ROOM_FACE_CPOINT - ROOM_FACE_CPOINT / 2;
        this.addChild( this.realy_user_face_1 , 1 );this.addChild( this.realy_user_face_2 , 1 );this.addChild( this.realy_user_face_3 , 1 );this.addChild( this.realy_user_face_4 , 1 );
    },
    //绘制要求好友跟解散房间按钮 - 及其绑定相应的事件
    draw_friend_and_dissolution:function(){

    },
    //ws-绘制新进用户头像以及名称等 - 14
    ws_user_welcome:function( DATA ){
        cc.log( DATA.log_data );
        //自己
        if( this.ws_user_1 == null && ROOM_WS_MY == 0 && DATA.log_data.mu != 0 ){
            this.ws_user_1    = new cc.LabelTTF( DATA.log_data.mn ,'Arial' , 24 );
            this.ws_user_1.x  = ROOM_FACE_CPOINT;
            this.ws_user_1.y  = ROOM_FACE_CPOINT * 2;
            this.addChild(this.ws_user_1,1);
            ROOM_WS_MY        = PB_USER_UID;
        }
        //下家
        if( this.ws_user_2 == null && ROOM_WS_XJ == 0 && DATA.log_data.xu != 0 ){
            this.ws_user_2    = new cc.LabelTTF( DATA.log_data.xn ,'Arial' , 24 );
            this.ws_user_2.x  = this.realy_size.width - ROOM_FACE_CPOINT;
            this.ws_user_2.y  = ROOM_FACE_CPOINT * 2;
            this.addChild(this.ws_user_2,1);
            ROOM_WS_XJ        = DATA.log_data.xu;
        }
        //对家
        if( this.ws_user_3 == null && ROOM_WS_DM == 0 && DATA.log_data.du != 0 ){
            this.ws_user_3    = new cc.LabelTTF( DATA.log_data.dn ,'Arial' , 24 );
            this.ws_user_3.x  = this.realy_size.width - ROOM_FACE_CPOINT;
            this.ws_user_3.y  = this.realy_size.height - 40;
            this.addChild(this.ws_user_3,1);
            ROOM_WS_DM        = DATA.log_data.du;
        }
        //上家
        if( this.ws_user_4 == null && ROOM_WS_SJ == 0 && DATA.log_data.su != 0 ){
            this.ws_user_4    = new cc.LabelTTF( DATA.log_data.sn ,'Arial' , 24 );
            this.ws_user_4.x  = ROOM_FACE_CPOINT;
            this.ws_user_4.y  = this.realy_size.height - 40;
            this.addChild(this.ws_user_4,1);
            ROOM_WS_SJ        = DATA.log_data.su;
        }
    },
    /*************************  ws监听计时器,用于不间断询问房间最新信息，若得到回复则进行画面操作 *****************************/
    draw_timer_room_realy:function(){
        if( PB_USER_UID <= 0 ){
            cc.log("用户当前未登录~");
        }else{
            cc.log("正在询问是否牌局"+ ROOM_ID +"最新进展...." + PB_USER_UID);
            PB_WS.send("n:" + PB_USER_UID + ":" + ROOM_ID + ":" + PB_MD_NUM);
        }
    }
    /*************************  ws监听计时器,用于不间断询问房间最新信息，若得到回复则进行画面操作 *****************************/
});
var RoomRealyScene = cc.Scene.extend({
    onEnter:function () {
        this._super();
        var realy      = new RoomRealyLayer();
        PL_Room_Realy  = realy;
        this.addChild(realy);
    }
});

